$(function(){
 
	var _mytable = {
		element:null,
		data:null,
		column:null,
		width:60,
		align:'left',
 
		_init:function(options){
			if(options.data != null){
				this.data = options.data;
			}
			if(options.column != null){
				this.column = options.column;
			}
			if(options.align != null){
				this.align = options.align;
			}
			this._render(options);
		},
 
		onclick:function(options){
			var obj = {},col,value;
			this.element.find("._mytable tbody tr").click(function(e){
				for(var i = 0 , len = options.column.length ; i < len ; i ++){
					col = options.column[i].name;
					value = $(this).find(".mytable_"+col).html();
					obj[col] = value
				}
				options.onclick(obj);
			})
		},
 
		_render:function(options){
			var _html = [];
			var visible = '';
			var width = this.width;
			_html.push('<table class="_mytable" style="text-align:'+this.align+'"><thead><tr>');
			for(var i = 0 , len = options.column.length ; i < len ; i ++){
				visible = options.column[i].visible == false ? 'none' : 'inline-block';
				width = options.column[i].width == null ? width : options.column[i].width;
				_html.push('<th style="display:'+visible+';width:'+width+'px;"');
				_html.push('class="mytable_'+options.column[i].name+'">'+options.column[i].label+'</th>');
			}
			_html.push('</tr></thead><tbody>');
 
			for(var i = 0 , len = options.data.length ; i < len ; i ++){
				_html.push('<tr>');
				for(var j = 0 , l = options.column.length ; j < l ; j ++){
					visible = options.column[j].visible == false ? 'none' : 'inline-block';
					width = options.column[j].width == null ? width : options.column[j].width;
					_html.push('<td class="mytable_'+options.column[j].name+'" style="display:'+visible+';width:'+width+'px;">');
					_html.push(options.data[i][options.column[j].name]+'</td>');
				}
				_html.push('</tr>');
			}
			_html.push('</tbody></table>');
 
			$(this.element).html(_html.join(''));
			this.onclick(options);
		}
	}
 
	$.fn.mytable = function(options){
		var _obj = _mytable;
		_obj.element = this;
		_obj._init(options);
		return _obj;
	}
 
})
 